package org.example.ch02.p53;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        try {
            int m = sc.nextInt();
            int n = sc.nextInt();

            int r = sc.nextInt();
            if (r != 90 && r != 180 && r != -90) {
                System.out.println("angle data error");
                return;
            }

            int[][] img = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    img[i][j] = sc.nextInt();
                    if (img[i][j] < 0 || img[i][j] > 255) {
                        System.out.println("matrix data error");
                        return;
                    }
                }
            }

            printRotated(img, r);

        } catch (Exception e) {
            System.out.println("data type error");
        }
    }

    static void printRotated(int[][] img, int angle) {
        int m = img.length;
        int n = img[0].length;

        if (angle == 90) {
            for (int j = n-1; j >= 0; j--) {
                for (int i = 0; i < m; i++) {
                    System.out.print(img[i][j] + " ");
                }
                System.out.println();
            }
        }
        else if (angle == -90) {
            for (int j = 0; j < n; j++) {
                for (int i = m-1; i >= 0; i--) {
                    System.out.print(img[i][j] + " ");
                }
                System.out.println();
            }
        }
        else {
            for (int i = m-1; i >= 0; i--) {
                for (int j = n-1; j >= 0; j--) {
                    System.out.print(img[i][j] + " ");
                }
                System.out.println();
            }
        }
    }
}
